package de.bht.fb6.cg1.exercise1;

/**
 * represents an integer range.
 * 
 * @author Dominik Eckelmann
 */
public class Range {

    /**
     * left range
     */
    private final int min;

    /**
     * right range
     */
    private final int max;

    /**
     * initialise a range
     * 
     * @param min   minimal value
     * @param max   maximal value
     */
    public Range(final int min, final int max) {
        if (min > max) {
            throw new IllegalArgumentException();
        }
        this.min = min;
        this.max = max;
    }

    /**
     * get the left range
     * 
     * @return minimal value
     */
    public final int getMin() {
        return min;
    }

    /**
     * get the right border
     * 
     * @return max value
     */
    public final int getMax() {
        return max;
    }
    
    /**
     * returns the range
     */
    @Override
    public String toString() {
        return "current range [" + min + ":" + max + "]";
    }

    /* Calculate a hashcode by the values from the Range
     * 
     * @return numerical hashcode
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + max;
        result = prime * result + min;
        return result;
    }

    /* Compares to ranges
     * 
     * @param obj another obj to compare with
     * @return true when the ranges are equal
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof Range)) {
            return false;
        }
        Range other = (Range) obj;
        if (max != other.max) {
            return false;
        }
        if (min != other.min) {
            return false;
        }
        return true;
    }
    
    
}
